package com.pdf.editor;

import com.pdf.editor.util.DecryptPDF;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import java.io.File;
import java.util.Objects;

public class DecryptDialogController {

    @FXML
    public TextField password;

    @FXML
    public Label tips;

    private File file;//pdf

    public void setFile(File file) {
        this.file = file;
    }

    /**
     * 开始PDF解密
     */
    @FXML
    public void decrypt() {
        if (Objects.nonNull(file) && file.getAbsolutePath().toLowerCase().endsWith(".pdf")) {
            String result = DecryptPDF.instance.decrypt(file, password.getText());
            if (Objects.nonNull(result)) {
                tips.setText(result);
            }else {
                tips.setText("解密完成");
            }
        } else {
            tips.setText("请选择PDF文件");
        }
    }


}
